#include "StdAfx.h"
#include "Parser.h"

Parser::Parser(void)
{
}

Parser::~Parser(void)
{
}

void Parser::InsertToken(vector<string> & tokens, string & token)
{
	if(token != "")
	{
		tokens.push_back(token);
	}
}

vector<string> Parser::MakeTokens(string commands)
{
	vector<string> tokens;
	string temp;

	for(int i = 0; i < commands.size(); i++)
	{
		if(commands[i] == ';')
		{
			InsertToken(tokens, temp);
			temp = "";
		}
		else if(commands[i] == '(')
		{
			InsertToken(tokens, temp);
			temp = "";			
			tokens.push_back("(");
		}
		else if(commands[i] == ')')
		{
			InsertToken(tokens, temp);
			temp = "";			
			tokens.push_back(")");
		}
		else if(commands[i] == '{')
		{
			tokens.push_back("{");
		}
		else if(commands[i] == '}')
		{
			InsertToken(tokens, temp);
			temp = "";			
			tokens.push_back("}");
		}
		else if(commands[i] != ' ')
		{
			temp  += commands[i];
		}
	}

	return tokens;
}